class DeviceAdapter:
    def __init__(self, protocol='aliyun'):
        self.protocol = protocol
        
    def send_command(self, device_info, command):
        """发送设备命令（适配不同协议）"""
        try:
            if self.protocol == 'aliyun':
                return self._send_aliyun_command(device_info, command)
            elif self.protocol == 'mqtt':
                return self._send_mqtt_command(device_info, command)
            elif self.protocol == 'http':
                return self._send_http_command(device_info, command)
            else:
                raise ValueError(f"不支持的协议: {self.protocol}")
        except Exception as e:
            return False, f"指令下发错误: {str(e)}"
    
    def _send_aliyun_command(self, device_info, command):
        """阿里云协议实现（使用DeviceCommandSender）"""
        from device_controller import command_sender
        return command_sender.send_bed_command(
            device_info.get('device_name', 'Spark'),
            device_info.get('product_key', 'k29cquyln1r'),
            command.get('servoangle', 0),
            command.get('servospeed', 2)
        )
    
    def _send_mqtt_command(self, device_info, command):
        """MQTT协议实现（预留）"""
        # 实现MQTT客户端逻辑
        print(f"📡 MQTT指令发送: {device_info} -> {command}")
        return True, "MQTT指令已发送"
    
    def _send_http_command(self, device_info, command):
        """HTTP协议实现（预留）"""
        # 实现HTTP客户端逻辑
        print(f"📡 HTTP指令发送: {device_info} -> {command}")
        return True, "HTTP指令已发送"
